package ltd.newbee.mall.util;

import lombok.Data;

// BaseResponse.java
@Data
public class BaseResponse<T> {
    private Boolean success;
    private String code;
    private String message;
    private T data;
    private Long timestamp;

    public BaseResponse() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setSuccess(true);
        response.setCode("SUCCESS");
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static <T> BaseResponse<T> fail(String code, String message) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    public static <T> BaseResponse<T> error(String message) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setSuccess(false);
        response.setCode("SYSTEM_ERROR");
        response.setMessage(message);
        return response;
    }
}
